package com.dplus.common.utils.util;
/**
 * 分页信息记录实体
 */
/**
 * @author jacking.jiao
 *
 */
public class PageBean {
	private int page=1;   //当前页
	private int pageSize=10;  //每页条数
	private long totalCount;  //总数
	private long totalPage;   //总页数
	private boolean hasPrevious; //是否有上一页
	private boolean hasNext; //是否有下一页
	private boolean bof;  //是否是首页
	private boolean eof;  //是否是尾页
	
/*	private int totalRow;	//总共记录数
	private int totalPage;	//总共页数
	private int currentPage = 1; //当前页，默认为1
	private int pageSize = 10;   //页的大小
*/
	
	
	public PageBean(){}
	public PageBean(long totalCount,int page, int pageSize){
		this.totalCount=totalCount;
		this.pageSize = pageSize;
		// 根据页大小和总记录数计算出总页数
				this.totalPage = countTotalPage(this.pageSize, this.totalCount);
				// 修正当前页
		setCurrentPage(page);
		init();
	}
	/**
	 * 仅用于首次，可能总计录为零
	 * @param page
	 * @param pageSize
	 */
	public PageBean(int page, int pageSize){
		this.pageSize = pageSize;
		if(page>0){
			this.page=page;
			
		}
	}
	
	// 修正计算当前页
	public void setCurrentPage(int page) {
        if(page>this.totalPage){
        	this.page=Long.valueOf(this.totalPage).intValue();        	
        }else if (page<1){
        	this.page=1;
        }
        else{
        	this.page=page;
        }
	}
	// 初始化信息
	private void init() {

		this.hasNext = hasNext();

		this.hasPrevious = hasPrevious();

		this.bof = isFirst();

		this.eof = isLast();

	}
	public boolean hasNext() {
		return page < this.totalPage;
	}
	public boolean hasPrevious() {
		return page > 1;
	}
	public boolean isFirst() {
		return page == 1;
	}
	public boolean isLast() {
		return page >= this.totalPage;
	}
	
	/**
	 * 得到当前页的结束条数
	 * @return
	 */
	public int getEndIndexget(){
		return page * pageSize;
	}
	/**
	 * 得到当前页所在开始条数
	 * @return
	 */
	public int getBeginIndex(){
		return page * pageSize - pageSize;
	}
	
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	/**
	 * 获取总页数
	 * @return
	 */
	public Long getTotalPage() {
		if(pageSize == 0){
			return new Long(0);
		}else
		if(totalCount%pageSize == 0){
			return totalCount / pageSize;
		} else {
			return totalCount / pageSize +1;
		}
	}

	
	public void setTotalPage(long totalPage) {
		this.totalPage = totalPage;
	}
	
	
	// 计算总页数
		public long countTotalPage(int pageSize, long totalCount) {
			long totalPage = 0;
			if(!(pageSize<=0)) totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
			return totalPage;
		}
	
	public Long getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(Long totalCount) {
		this.totalCount = totalCount;
	}
	public static boolean isEmpty(PageBean pageBean){
		if(pageBean == null){
			return true;
		}
		return false;
	}
	public String toString(){
		return "page:"+this.page+",pageSize:"+this.pageSize+",totalCount:"+this.totalCount;
	}
	public boolean isHasPrevious() {
		return hasPrevious;
	}
	public void setHasPrevious(boolean hasPrevious) {
		this.hasPrevious = hasPrevious;
	}
	public boolean isHasNext() {
		return hasNext;
	}
	public void setHasNext(boolean hasNext) {
		this.hasNext = hasNext;
	}
	public boolean isBof() {
		return bof;
	}
	public void setBof(boolean bof) {
		this.bof = bof;
	}
	public boolean isEof() {
		return eof;
	}
	public void setEof(boolean eof) {
		this.eof = eof;
	}
	
	
	
}
